home *** CD-ROM | disk | FTP | other *** search
- /* s t d i o
- *
- * Author: C. E. Chew
- * Date: August 1989
- *
- * (C) Copyright C E Chew
- *
- * Feel free to copy, use and distribute this software provided:
- *
- * 1. you do not pretend that you wrote it
- * 2. you leave this copyright notice intact.
- *
- * Definitions and user interface for the stream io package.
- *
- * Patchlevel 1.2
- *
- * Edit History:
- * 06-Sep-1989 Cast (x) to (unsigned char) in call to _flsbuf().
- * 05-Sep-1989 Mods for Gnu C (really for any ansi C) ++jrb
- * 05-Sep-1989 Make self reliant by removing dependency on proto.h
- * and varargs.h.
- * 04-Sep-1989 Undo change to putc() since it makes it so much
- * more complicated and makes so little difference
- * to the speed.
- * 03-Sep-1989 Alter putc() to cope with line buffered streams.
- * This makes processing of line buffered streams
- * faster since no calls to _flsbuf is required
- * unless the buffer fills.
- * 31-Aug-1989 Change to use _end as suggested by Bruce Evans
- * many moons ago.
- */
-
- #if !defined(__STDIO__)
-
- #define __STDIO__
-
- #if defined(__STDC__)
- # if !defined(__NO_PROTO__)
- # define __STDIO_P__(x) x
- # else
- # define __STDIO_P__(x) ()
- # endif
- #else
- # define __STDIO_P__(x) ()
- #endif
-
- #define BUFSIZ 1024
- #define _NFILE 20
- #define NFILES _NFILE /* backward compatibilty */
-
- extern struct _iobuf {
- unsigned char *_end; /* point at end of buffer */
- unsigned char *_ptr; /* pointer into buffer */
- unsigned char *_base; /* base of buffer */
- int _bufsiz; /* size of buffer */
- short _flag; /* flags */
- char _file; /* channel number */
- unsigned char _buf; /* small buffer */
- } *_iop[_NFILE];
-
- #define _IOFBF 0000 /* fully buffered io */
- #define _IOREAD 0001 /* opened for reading */
- #define _IOWRITE 0002 /* opened for writing */
- #define _IONBF 0004 /* unbuffered */
- #define _IOMYBUF 0010 /* allocated buffer */
- #define _IOEOF 0020 /* eof encountered */
- #define _IOERR 0040 /* error encountered */
- #define _IOSTRING 0100 /* strings */
- #define _IOLBF 0200 /* line buffered */
- #define _IORW 0400 /* opened for reading and writing */
-
- #define SEEK_SET 0 /* seek from beginning */
- #define SEEK_CUR 1 /* seek from here */
- #define SEEK_END 2 /* seek from end */
-
- #if defined(__STDC__)
- # define NULL ((void *)0L) /* null pointer */
- #else
- # define NULL (0) /* null pointer */
- #endif
- #define FILE struct _iobuf /* FILE structure */
- #define EOF (-1) /* eof flag */
-
- #define stdin (_iop[0])
- #define stdout (_iop[1])
- #define stderr (_iop[2])
-
- #define getc(p) ((p)->_ptr<(p)->_end?(int)(*(p)->_ptr++)\
- :_filbuf(p))
- #define getchar() getc(stdin)
-
- #define putc(x,p) ((p)->_ptr<(p)->_end\
- ?(int)(*(p)->_ptr++=(unsigned char)(x))\
- :_flsbuf((unsigned char)(x),(p)))
- #define putchar(x) putc(x,stdout)
-
- #define fileno(p) ((p)->_file)
-
- #define feof(p) (((p)->_flag&_IOEOF)!=0)
- #define ferror(p) (((p)->_flag&_IOERR)!=0)
- #define clearerr(p) ((p)->_flag&=~(_IOEOF|_IOERR))
-
- /* minix-ST gnu-c library specific -- defines CONST etc */
- #if defined(__GNUC__)
- # if !defined(__NO_PROTO__)
- # include <std.h>
- # endif
- #endif
-
- #if !defined(CONST)
- # define CONST /* */
- #endif
-
- int _filbuf __STDIO_P__((FILE *));
- int _flsbuf __STDIO_P__((unsigned char, FILE *));
-
- FILE *fopen __STDIO_P__((CONST char *, CONST char *));
- FILE *fdopen __STDIO_P__((int, CONST char *));
- FILE *freopen __STDIO_P__((CONST char *, CONST char *, FILE *));
- int fflush __STDIO_P__((FILE *));
- int fclose __STDIO_P__((FILE *));
-
- long ftell __STDIO_P__((FILE *));
- int fseek __STDIO_P__((FILE *, long, int));
- void rewind __STDIO_P__((FILE *));
-
- int fgetc __STDIO_P__((FILE *));
- int fputc __STDIO_P__((int, FILE *));
- int fread __STDIO_P__((void *, unsigned int,
- unsigned int, FILE *));
- int fwrite __STDIO_P__((CONST void *, unsigned int,
- unsigned int, FILE *));
- int getw __STDIO_P__((FILE *));
- int putw __STDIO_P__((int, FILE *));
- char *gets __STDIO_P__((char *));
- char *fgets __STDIO_P__((char *, int, FILE *));
- int puts __STDIO_P__((CONST char *));
- int fputs __STDIO_P__((CONST char *, FILE *));
-
- int ungetc __STDIO_P__((int, FILE *));
-
- #if !defined(__SRC__)
- int printf __STDIO_P__((CONST char *, ...));
- int fprintf __STDIO_P__((FILE *, CONST char *, ...));
- char * sprintf __STDIO_P__((char *, CONST char *, ...));
- int scanf __STDIO_P__((CONST char *, ...));
- int fscanf __STDIO_P__((FILE *, CONST char *, ...));
- int sscanf __STDIO_P__((CONST char *, CONST char *, ...));
- #else
- int printf __STDIO_P__((CONST char *, int));
- int fprintf __STDIO_P__((FILE *, CONST char *, int));
- char * sprintf __STDIO_P__((char *, CONST char *, int));
- int scanf __STDIO_P__((CONST char *, int));
- int fscanf __STDIO_P__((FILE *, CONST char *, int));
- int sscanf __STDIO_P__((CONST char *, CONST char *, int));
- #endif /* __SRC__ */
-
- int vprintf __STDIO_P__((CONST char *, char *));
- int vfprintf __STDIO_P__((FILE *, CONST char *, char *));
- int vsprintf __STDIO_P__((char *, CONST char *, char *));
- int vscanf __STDIO_P__((CONST char *, char *));
- int vfscanf __STDIO_P__((FILE *, CONST char *, char *));
- int vsscanf __STDIO_P__((CONST char *, CONST char *, char *));
-
- void setbuf __STDIO_P__((FILE *, char *));
- int setvbuf __STDIO_P__((FILE *, char *, int, unsigned int));
- #endif /* __STDIO__ */
-
-